using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Employers_resumemanager : System.Web.UI.Page
{
    string jobID = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session.Contents["rcuserid"] == null)
        {
            Response.Redirect("login.aspx");
        }
         
        if (!IsPostBack)
            ShowData();

    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        ShowData();
        GridView1.PageIndex = e.NewPageIndex;
    }
    void ShowData()
    {
        try
        {
            ControlHelper cls = new ControlHelper("");
            cls.CommandText = "SPViewAppliedResumes";
            cls.ParameterCollection = new string[2] { "@RecruiterID", "@JobID" };
            cls.ValueCollection = new string[2] { 
            Convert.ToString(Session.Contents["rcuserid"]), "0"};
            cls.CommandType = CommandType.StoredProcedure;
            cls.InitProperties();
            cls.FillDataTableToGridView(this.GridView1, 10, 10, PagerButtons.NumericFirstLast);

        }
        catch (Exception ex)
        {
            Literal1.Text = ex.Message;
        }
    }

    protected void btnDelete_Click(object sender, EventArgs e)
    {
        string resumeID = GetIDToAct();
        if (resumeID != "")
        {

            SqlServerProvider sqlServerProvider
                        = new SqlServerProvider();
            foreach (string resume in resumeID.Split(','))
                sqlServerProvider.DeleteAppliedResume(
                Convert.ToString(Session["rcuserid"]), "0", resume);
            ShowData();
        }
    }


    string GetIDToAct()
    {

        string resumeID = "";
        foreach (GridViewRow gridViewRow in GridView1.Rows)
        {
            CheckBox checkBox = (CheckBox)
            gridViewRow.FindControl("chkResumeID");
            if (checkBox.Checked)
            {
                try
                {
                    resumeID +=
                    gridViewRow.Cells[1].Text + ",";
                }
                catch (Exception ex)
                {
                    Literal1.Text = ex.Message;
                }
            }

        }
        if (resumeID != "")
        {
            resumeID = resumeID.Substring(0, resumeID.Length - 1);
        }
        return resumeID;
    }
    protected void btnAccept_Click(object sender, EventArgs e)
    {
        string resumeID = GetIDToAct();
        if (resumeID != "")
        {

            SqlServerProvider sqlServerProvider
                        = new SqlServerProvider();
            foreach (string resume in resumeID.Split(','))
                sqlServerProvider.ChangeStatusOfResume(
                Convert.ToString(Session["rcuserid"]), "0", resume, "2");
            ShowData();
        }
    }
    protected void btnReject_Click(object sender, EventArgs e)
    {
        string resumeID = GetIDToAct();
        if (resumeID != "")
        {

            SqlServerProvider sqlServerProvider
                        = new SqlServerProvider();
            foreach (string resume in resumeID.Split(','))
                sqlServerProvider.ChangeStatusOfResume(
                Convert.ToString(Session["rcuserid"]), "0", resume, "1");
            ShowData();
        }
    }
    protected void btnKeep_Click(object sender, EventArgs e)
    {
        string resumeID = GetIDToAct();
        if (resumeID != "")
        {

            SqlServerProvider sqlServerProvider
                        = new SqlServerProvider();
            foreach (string resume in resumeID.Split(','))
                sqlServerProvider.ChangeStatusOfResume(
                Convert.ToString(Session["rcuserid"]), "0", resume, "3");
            ShowData();
        }
    }
}
